/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#ifndef __NUMERIC_TEXT_EDIT_H__
#define __NUMERIC_TEXT_EDIT_H__

#include <QtGui/QWidget>
#include <QtGui/QLineEdit>
#include <QtGui/QLabel>
#include <QtGui/QGridLayout>

namespace PQBuilder
{
	//only use Qt to construct our widget
	class NumericTextEdit :
		public QWidget
	{
	Q_OBJECT
	public:
		NumericTextEdit(QWidget *parent = 0);
		NumericTextEdit(float value,QWidget *parent = 0);
		void setFloat(float value);
		inline void inc()
		{
			float value=_value+_deltaValue;
			setFloat(value);
		}

		inline void dec()
		{
			float value=_value-_deltaValue;
			setFloat(value);
		}

		inline float getFloat()
		{
		return _value;
		}

		inline void setDeltaValue(float value)
		{
		_deltaValue=value;
		}

		inline void setMaxValue(float value)
		{
		_maxValue=value;
		}

		inline void setMinValue(float value)
		{
		_minValue=value;
		}

	protected:
		void mousePressEvent(QMouseEvent *evt);
		void mouseDoubleClickEvent(QMouseEvent *evt);
		void mouseMoveEvent(QMouseEvent *evt);
		void mouseReleaseEvent(QMouseEvent *evt);
		void leaveEvent (QEvent *evt);

	public slots:
		void OnTextFinished();
	private:
		void textEditFinished();
	private:
		bool _mouseLeftPress;
		bool _textEdit;
		float _value;
		float _deltaValue;

		float _maxValue;
		float _minValue;
		QPoint _mousePosition;

		QLineEdit* _lineEdit;
		QLabel* _label;
		QGridLayout* _layout;
	};
}

#endif
